var http = require('../../utils/http.js');
var QQMapWX = require('../../utils/qqmap-wx-jssdk.min.js');
var QQMapKey = require('../../utils/http.js').QQMapKey;
var util = require('../../utils/util.js');
var unionid = wx.getStorageSync('thisCode');
Page({

    data: {
        scaleMap:14,
        latitude:0,
        longitude:0,
        nearMarkerArr:[]
    },

    onLoad: function (options) {
        var unionid = wx.getStorageSync('thisCode');
        wx.getLocation({
            type: 'gcj02',
                success: res=>{
                    console.log(res)
                    var latitude = Number(res.latitude);
                    var longitude = Number(res.longitude);
                    var speed = res.speed
                    var accuracy = res.accuracy
                    this.setData({
                        latitude:latitude,
                        longitude:longitude,
                    })
                    wx.showLoading({title: '加载中...',})
                    http._post('Nearby/nearby',{
                        unionid:unionid,
                        longitude:longitude,
                        latitude:latitude
                    },res=>{
                        let data = res.data;
                        let nearMarkerArr = [];

                        if(data.status == 1){
                            data.store_list.find(item=>{
                                nearMarkerArr.push(item)
                            })
                            this.setData({
                                nearMarkerArr:nearMarkerArr
                            })
                        }
                    },res=>{})    
                },
                fail:res=>{
                wx.reLaunch({
                  url: '/pages/wsq/wsq'
                })
            }
        })
    },
    clickBjOrigin(e){
        let markerId = e.markerId;
        let nearMarkerArr = this.data.nearMarkerArr;
        let item = nearMarkerArr.find(item=>{
            return item.id == markerId
        })
        console.log(item)
        http.showModal1('是否前往'+item.title+'-'+item.callout.content,true,()=>{
            wx.openLocation({
              latitude: Number(item.latitude),
              longitude: Number(item.longitude),
              scale: 28
            })
        },()=>{})
    },
    onReady: function () {

    },

    onShow: function () {
        wx.hideShareMenu();
    },  

    onHide: function () {

    },

    onUnload: function () {

    },

    onPullDownRefresh: function () {

    },

    onReachBottom: function () {

    }
})